package com.reactor.demo.router;

import com.reactor.demo.handler.FirstHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

/**
 * @author jing
 * @description
 * @date 2018/12/8 0008 23:56
 */
@Configuration
public class FirstRouter {

    @Autowired
    FirstHandler firstHandler;

    @Bean
    public RouterFunction<ServerResponse> timeRouter(){
        return route(GET("/time"), req -> firstHandler.getTime(req))
                .andRoute(GET("/date"), firstHandler::getDate)
                .andRoute(GET("/message"),firstHandler::sendMessage);
    }
}
